// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//


#include <pollux/functions/lib/aggregates/average_aggregate_base.h>

namespace kumo::pollux::functions::aggregate {
    void checkAvgIntermediateType(const TypePtr &type) {
        POLLUX_USER_CHECK(
            type->is_row() || type->is_varbinary(),
            "Input type for final average must be row type or varbinary type.");
        if (type->kind() == TypeKind::VARBINARY) {
            return;
        }
        POLLUX_USER_CHECK(
            type->childAt(0)->kind() == TypeKind::DOUBLE ||
            type->childAt(0)->isLongDecimal(),
            "Input type for sum in final average must be double or long decimal type.");
        POLLUX_USER_CHECK_EQ(
            type->childAt(1)->kind(),
            TypeKind::BIGINT,
            "Input type for count in final average must be bigint type.");
    }
} // namespace kumo::pollux::functions::aggregate
